package net.gpai.logger;

import org.apache.logging.log4j.LogManager

/**
 * actual表示kmp多平台具体的实现
 */
actual fun logger(name: String): KmpLogger = Log4j2KmpLogger(LogManager.getLogger(name))

/**
 * 私有的类,实现commonMain模块的KmpLogger接口
 */
private class Log4j2KmpLogger(
    private val delegate: org.apache.logging.log4j.Logger
) : KmpLogger {

    override fun debug(msg: String, vararg param: Any?) = delegate.debug(msg, *param)      // 展开变参

    override fun info(msg: String, vararg param: Any?) = delegate.info(msg, *param)

    override fun warn(msg: String, vararg param: Any?) = delegate.warn(msg, *param)

    override fun error(msg: String, vararg param: Any?) = delegate.error(msg, *param)

    override fun error(msg: String, t: Throwable?, vararg param: Any?) =
        delegate.error(msg, *param, t)   // 异常放在最后一个，Log4j2 会识别
}